/**
 * <p>选择API基本信息的查询grid</p>
 * xtype = cceafselectapi_basegrid

 * @module Ext-ux-cceaf-control
 * @class cceaf.control.SelectApi_baseGrid
 * @extends Ext.grid.Panel
 * @since 1.0
 */
Ext.define('cceaf.control.msg.SelectSysUser',{
	extend: 'Ext.grid.Panel', 
    alias: 'widget.cceafselectsysuser',
    requires: [
               'cceaf.control.TextItem',
       	       'cceaf.control.TextField',
               'cceaf.control.CodeField',
               'cceaf.control.NumberField',
               'cceaf.control.TextArea'
             
   	],
   	/*
	
*/
  	
	constructor: function(config){
		config = config || {};
		
		Ext.define('_SysUserModel', {
		    extend: 'Ext.data.Model',
		    fields: [
				  {name: 'userid'}, 
				  {name: 'groupid'}, 
				  {name: 'groupname'}, 
				  {name: 'passwd'}, 
				  {name: 'operatorname'},
				  {name: 'telphone'}, 
				  {name: 'email'}, 
				  {name: 'deptid'}, 
				  {name: 'description'}, 
				  {name: 'sex'}, 
				  {name: 'sexName'},
				  {name: 'birthday'}, 
				  {name: 'idcard'}, 
				  {name: 'skin'}, 
				  {name: 'valid'},
				  {name: 'validName'}	
		    ]
		});
	    
		//定义数据源
	    var ds = new Ext.data.Store({
	    	proxy: {
	    		type: 'ajax',
	    		url: 'sysmanager/user!query.action',
	    		reader: {
					type: 'json',
					root: 'data',
					totalProperty: 'totalCount',
					messageProperty: 'message'
				}
			},
			
	        listeners: {
	        	'load': function() {
	        		var jr = ds.getProxy().getReader();
	        		var message = jr.jsonData.message;
	        		cceaf.util.ExtHelper.showInfoDialog(message);
	        	},
	        	'loadexception': function() {
	        		var jr = ds.getProxy().getReader();
	        		if(jr.jsonData){
		        		var message = jr.jsonData.message;
		        		cceaf.util.ExtHelper.showErrorDialog(message);
	        		}
	        		else{
	        			cceaf.util.ExtHelper.showErrorDialog("返回无效的JSONDATA数据");
	        		}
	        	}
	        },
	        
	        autoDestroy: true,  
	    	pageSize: szpshang.Global.PAGE_SIZE,
	    	model: '_SysUserModel'
	    });
	    
	    //列序号模式
	    //var nm = new Ext.grid.RowNumberer();
	    //多选列模式
		//var selModel = new Ext.selection.CheckboxModel();
	    var selModel = new Ext.selection.RowModel();
	    
		//查询对象
	    function btnQuery_click(){
	    	var api_baseGrid = this.up('gridpanel');
	    	
	    	var userid=api_baseGrid.down("[name=q_userid]").getValue();
	    	var groupname=api_baseGrid.down("[name=q_groupname]").getValue();
	    	var idcard=api_baseGrid.down("[name=q_idcard]").getValue();
	    	var sex=api_baseGrid.down("[name=q_sex]").getValue();
	    	var valid=api_baseGrid.down("[name=q_valid]").getValue();


	    	ds.proxy.extraParams = {
	    			q_userid:userid,
	    			q_groupname:groupname,
	    			q_idcard: idcard,
	   				q_sex: sex,
 					q_valid: valid
		    };
	    	ds.load({params:{isquery:true}});
	    }
	    
	  	//重置查询条件
	    function btnReset_click(){
	    	var api_baseGrid = this.up('gridpanel');
	    	
	    	api_baseGrid.down("[name=q_userid]").setValue("");
	    	api_baseGrid.down("[name=q_groupname]").setValue("");
	    	api_baseGrid.down("[name=q_idcard]").setValue("");
	    	api_baseGrid.down("[name=q_sex]").setValue("");
	    	api_baseGrid.down("[name=q_valid]").setValue("");

	    	
	    }
	    
	    
	   
	 	//定义表格列
	    var columns = [
	    	  {xtype: 'rownumberer'},
	          {dataIndex: 'userid', header: '用户编号', sortable: true},
	          {dataIndex: 'groupid', header: '组织机构', sortable: true,renderer:  cceaf.Global.cceafGroupRenderer, flex: 2},
	          {dataIndex: 'operatorname', header: '操作员名称', sortable: true, flex: 1},
	          {dataIndex: 'telphone', header: '联系电话', sortable: true, flex: 1},
	          {dataIndex: 'email', header: '邮箱地址', sortable: true, flex: 2},
	          {dataIndex: 'sex', header: '性别', sortable: true,renderer: cceaf.Global.cceafCodeRenderer('XB'), flex: 1},
	          {dataIndex: 'birthday', header: '出生年月', sortable: true, renderer:cceaf.Global.cceafDateRenderer, flex: 1},
	          {dataIndex: 'idcard', header: '身份证号', sortable: true, flex: 2},
	          {dataIndex: 'valid', header: '是否有效', sortable: true,renderer: cceaf.Global.cceafCodeRenderer('SF'), flex: 1}
	    ];
	    
		Ext.applyIf(config, {
			//id:'_selectApi_baseGrid',
	    	title:'选择用户编号',
	        border: true,
	        frame: true,
	        //height: cceaf.util.ExtHelper.getBodyHeight(),
	        //width: document.body.scrollWidth,
	        store: ds,
	        //sm:sm,
	        selModel: selModel,
	        columns: columns,
	        loadMask: {msg:'正在加载数据，请稍侯……'},
	        
	        viewConfig: {
				forceFit:true,
				enableRowBody:true,
				getRowClass : function(record, rowIndex, p, ds){
					return '';
				}
			},
			
			dockedItems:[{
				xtype : 'toolbar',  
                dock : 'top',  
                items:[
						{xtype: 'cceaftbtext', text: '用户编号'},
						{xtype: 'cceaftextfield',name: 'q_userid'},  //查询的时候必须设置name属性
						{xtype: 'cceaftbtext', text: ''},
						{xtype: 'cceaftbtext', text: '机构'},
						{xtype: 'cceafgrouppicker',name: 'q_groupname',idOfGroupid: 'q_groupid'},
						{xtype: 'textfield',name: 'q_groupid',hidden: true},
						{xtype: 'cceaftbtext', text: ''},
						{xtype: 'cceaftbtext', text: '身份证号'},
						{xtype: 'cceaftextfield',name: 'q_idcard',maxLength:13},
			        	
					]
			},{
				xtype : 'toolbar',  
                dock : 'top',  
                items:[
						{xtype: 'cceaftbtext', text: '性别'},
						{xtype: 'cceafcodefield',codeType: 'XB',name: 'q_sex'},
						{xtype: 'cceaftbtext', text: ''},
						{xtype: 'cceaftbtext', text: '是否有效'},
						{xtype: 'cceafcodefield',codeType: 'SF',name: 'q_valid'},
			        	{xtype: 'tbfill'},
			        	{itemId: 'btnQuery', iconCls: 'page_queryIcon', text: ' 查询 ', pressed: true,handler: btnQuery_click},
			        	'-',
			        	{itemId: 'btnReset', iconCls: 'page_resetIcon', text: ' 重置 ', pressed: true,handler: btnReset_click}
					]
			},{
				xtype: 'pagingtoolbar',
				store: ds,
                dock: 'bottom',  
                displayInfo: true,
                displayMsg:'当前显示 {0} - {1}条记录 /共 {2}条记录',
	            emptyMsg:'无显示数据'
			}],
	        
			listeners: {
	        	'render': function() {
	        		//tbarButton.render(queryGrid.tbar);
	        	},
	        	'itemdblclick': function() {
	        		this.selectRow();
	        	},
	        	'keydown': function(e){
	        		if(e.keyCode == 13 && this.getSelectionModel().getLastSelected() != null){
	        			this.selectRow();
	        		}
	        	}
	        },
	        
	        selectRow: function(){
	        	var selectApi_baseGrid = this;
	        	
	        	//获取API字段的父对象
	        	var api_baseFieldFather = this.fee.FeeUser.up();
	        	
        		//填充数据到父窗口的控件
        		if(selectApi_baseGrid.idOfuserid != null && selectApi_baseGrid.idOfuserid != ""){
        			api_baseFieldFather.down('[name=' + selectApi_baseGrid.idOfuserid + ']').setValue(this.getSelectionModel().getLastSelected().get("userId"));
        		}
        		selectApi_baseGrid.api_baseField.setValue(this.getSelectionModel().getLastSelected().get("api_name"));
        		
        		
	        }
	        
		});
		
		cceaf.control.msg.SelectSysUser.superclass.constructor.apply(this, arguments);
	},
	
	
	nameOfApi_id: null,
	

	api_baseField: null
	
});